<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title th:text="${info.infoTitle}">资讯详情</title>
    <style>
        /* --- 全局和基础样式 (与之前页面完全一致) --- */
        :root {
            --sidebar-width: 240px;
            --primary-color: #007bff;
            --light-gray: #f8f9fa;
            --border-color: #dee2e6;
            --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            background-color: #f4f5f7;
            margin: 0;
            color: #333;
        }

        /* --- 主要布局 --- */
        /* 模拟的侧边栏样式 */
        .teacher-sidebar-placeholder {
            position: fixed; top: 0; left: 0; height: 100%;
            width: var(--sidebar-width); background-color: #fff;
            box-shadow: 2px 0 5px rgba(0,0,0,0.05); z-index: 1000;
            padding: 20px; box-sizing: border-box; border-right: 1px solid #e9ecef;
        }
        .teacher-sidebar-placeholder h3 { margin-top: 0; color: var(--primary-color); }
        .teacher-sidebar-placeholder ul { list-style: none; padding: 0; }
        .teacher-sidebar-placeholder li a { display: block; padding: 10px; text-decoration: none; color: #333; border-radius: 4px; }
        .teacher-sidebar-placeholder li a:hover { background-color: #f1f1f1; }

        .main-content {
            margin-left: var(--sidebar-width);
            padding: 30px;
        }

        .article-container {
            max-width: 900px;
            margin: 0 auto;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: var(--card-shadow);
            padding: 30px 40px;
        }

        /* --- 文章内容样式 --- */
        .article-header h1 {
            font-size: 2.2em;
            margin: 0 0 10px;
            color: #111;
        }

        .article-meta {
            color: #6c757d;
            font-size: 0.9em;
            margin-bottom: 25px;
            border-bottom: 1px solid var(--border-color);
            padding-bottom: 20px;
        }

        .article-body img {
            max-width: 100%;
            height: auto;
            border-radius: 8px;
            margin: 15px 0;
        }

        /* 优化 th:utext 渲染出的内容的样式 */
        .article-body {
            line-height: 1.8;
            font-size: 1.1em;
            color: #212529;
        }
        .article-body p { margin: 0 0 1.5em 0; }
        .article-body h2 { font-size: 1.6em; margin: 1.5em 0 1em; }
        .article-body h3 { font-size: 1.4em; margin: 1.5em 0 1em; }
        .article-body ul, .article-body ol { padding-left: 25px; }
        .article-body blockquote {
            border-left: 4px solid var(--primary-color);
            padding-left: 20px;
            margin: 1.5em 0;
            color: #555;
            background-color: var(--light-gray);
            font-style: italic;
        }

        /* --- 评论区样式 --- */
        .comments-section {
            margin-top: 40px;
            padding-top: 30px;
            border-top: 1px solid var(--border-color);
        }
        .comments-section h3 {
            font-size: 1.5em;
            margin: 0 0 20px 0;
        }

        /* 评论表单 */
        .comment-form textarea {
            width: 100%;
            padding: 12px;
            border: 1px solid var(--border-color);
            border-radius: 4px;
            font-size: 1em;
            line-height: 1.5;
            resize: vertical;
            transition: border-color 0.2s, box-shadow 0.2s;
        }
        .comment-form textarea:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
        }
        .form-actions {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-top: 10px;
        }
        #char-counter { font-size: 0.9em; color: #6c757d; }

        /* 评论列表 */
        .comment-list {
            margin-top: 30px;
        }
        .comment-item {
            display: flex;
            align-items: flex-start;
            gap: 15px;
            padding: 20px 0;
            border-bottom: 1px solid #f1f1f1;
        }
        .comment-item:last-child { border-bottom: none; }

        .comment-avatar {
            width: 45px;
            height: 45px;
            border-radius: 50%;
            background-color: var(--primary-color);
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            font-size: 1.2em;
            flex-shrink: 0;
        }
        .comment-body { flex-grow: 1; }
        .comment-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 5px;
        }
        .comment-header strong { color: #333; }
        .comment-header small { font-size: 0.85em; color: #888; }
        .comment-content {
            margin: 0;
            word-wrap: break-word;
        }

        /* 统一样式按钮 */
        .btn {
            display: inline-block; font-weight: 500; text-align: center; cursor: pointer;
            background-color: var(--primary-color); border: 1px solid var(--primary-color);
            padding: 10px 20px; font-size: 1em; border-radius: 4px;
            transition: all 0.2s ease-in-out; color: #fff;
        }
        .btn:hover { filter: brightness(90%); }

    </style>
</head>
<body>
<div th:replace="~{fragments/header :: header}">
    <div class="teacher-sidebar-placeholder">
        <h3>教师后台</h3>
        <ul>
            <li><a href="#">仪表盘</a></li>
            <li><a href="#" style="background-color: #e9ecef; font-weight: bold;">资讯中心</a></li>
            <li><a href="#">学生管理</a></li>
            <li><a href="#">个人设置</a></li>
        </ul>
    </div>
</div>

<div class="main-content">
    <div class="article-container">
        <div class="article-header">
            <h1 th:text="${info.infoTitle}">资讯标题加载中...</h1>
            <p class="article-meta">
                作者: <span th:text="${info.teacherName}">作者名</span> |
                发布于: <span th:text="${#temporals.format(info.createTime, 'yyyy-MM-dd HH:mm')}">2025-06-16 10:37</span>
            </p>
        </div>

        <div class="article-body">
            <img th:if="${info.infoImage != null and info.infoImage != '/images/default-info.png'}"
                 th:src="@{${info.infoImage}}" alt="资讯图片">

            <div th:utext="${info.infoMain}">
                <p>这里是资讯的正文内容，正在加载中... 这部分内容可以包含 <strong>加粗</strong>、<em>斜体</em> 以及其他 HTML 格式。</p>
                <blockquote>这是一个引用的例子，用于突出显示某些文本。</blockquote>
                <p>这是正文的另一段，以展示段落间的间距。</p>
            </div>
        </div>

        <div class="comments-section">
            <h3>发表评论</h3>
            <div class="comment-form">
                <form th:action="@{/info/detail/{id}/comment(id=${info.id})}" th:object="${newComment}" method="post">
                    <textarea id="comment-content" th:field="*{content}" placeholder="分享你的见解吧！" rows="4" required maxlength="500"></textarea>
                    <div class="form-actions">
                        <span id="char-counter">0 / 500</span>
                        <button type="submit" class="btn">发表</button>
                    </div>
                </form>
            </div>

            <div class="comment-list">
                <div th:if="${#lists.isEmpty(comments)}" style="text-align: center; padding: 30px 0; color: #888;">
                    暂无评论，期待您的精彩发言！
                </div>
                <div th:each="comment : ${comments}" class="comment-item">
                    <div class="comment-avatar" th:text="${#strings.substring(comment.username, 0, 1)}">U</div>
                    <div class="comment-body">
                        <div class="comment-header">
                            <strong th:text="${comment.username}">用户名</strong>
                            <small th:text="${#temporals.format(comment.createTime, 'yyyy-MM-dd HH:mm')}">2025-06-16 10:30</small>
                        </div>
                        <p class="comment-content" th:text="${comment.content}">这是一条示例评论内容。</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        // 评论输入框字数统计功能
        const textarea = document.getElementById('comment-content');
        const charCounter = document.getElementById('char-counter');

        if (textarea && charCounter) {
            const maxLength = textarea.getAttribute('maxlength');

            const updateCounter = () => {
                const currentLength = textarea.value.length;
                charCounter.textContent = `${currentLength} / ${maxLength}`;
            };
            updateCounter(); // 页面加载时初始化
            textarea.addEventListener('input', updateCounter); // 输入时更新
        }
    });
</script>

</body>
</html>